<template>
  <div>
    <el-row>
      <el-button size="small" type="primary" @click="dialog_newly = true" icon="el-icon-folder-add">新增</el-button>
    </el-row>
    <el-divider></el-divider>
    <!-- 表格 -->
    <el-table size="medium" :data="tableData" tooltip-effect="dark" style="width: 100%" border>
      <el-table-column prop="roleName" label="角色" align="center" width="300"></el-table-column>
      <el-table-column prop="message" label="短语内容" align="center" width="300"></el-table-column>
      <el-table-column prop="handle" label="操作" align="center">
        <template slot-scope="scope">
          <el-button size="mini" type="danger" plain @click="deleteSay({ id: scope.row.id })">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 添加短语弹窗 -->
    <el-dialog title="添加" :visible.sync="dialog_newly">
      <el-form :label-position="labelPosition" label-width="100px" style="margin-left:100px;">
        <el-form-item label="角色分配 :">
          <el-select v-model="form.roleId" placeholder="请选择角色" style="width:250px;" clearable>
            <el-option v-for="item in Role" :key="item.id" :label="item.roleName" :value="item.id"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="短语 :">
          <el-input v-model="form.message" style="width:250px;" placeholder="请输入" clearable></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialog_newly = false">取 消</el-button>
        <el-button type="primary" @click="addSay" class="dialogbutton">确 定</el-button>
      </div>
    </el-dialog>
    <!-- 添加报修类型弹窗 -->

  </div>
</template>

<script>
import { getSays, addSay, deleteSay } from '_api/FlowManage/FastSay/index.js'
import { getRoles } from '_api/RoleManage/index.js'

export default {
  data() {
    return {
      labelPosition: "left",
      dialog_newly: false,
      tableData: [],
      form: {
        message: "",
        roleId: ""
      },
      Role: ""

    }
  },
  methods: {
    // 获取角色
    getRole() {
      getRoles().then(res => {
        if (res.status == 200) {
          this.Role = res.data.data
        }
        this.getSays()
      })
    },
    // 删除短语
    deleteSay(e) {
      this.$confirm('此操作将删除该短语, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteSay(e).then(res => {
          if (res.status == 200) {
            this.$message({
              message: '删除成功!',
              duration: 1000,
              type: 'success',
              onClose: () => {
                this.getSays()
              }
            })
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    //添加短语
    addSay() {
      addSay(this.form).then(res => {
        if (res.status == 200) {
          this.dialog_newly = false
          this.$message({
            message: '添加成功!',
            duration: 1000,
            type: 'success',
            onClose: () => {
              this.getSays()
            }
          })
        }
      })
    },
    //查询短语
    getSays() {
      getSays().then(res => {
        if (res.status == 200) {
          this.tableData = res.data.data
        }
      })
    }
  },
  created() {
    this.getRole()
  },
};
</script>
<style lang="scss" scoped></style>
